//
//  KBaseSearchCommandDTO.m
//  KutulusLaw
//
//  Created by Mahmood1 on 12/10/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "KBaseSearchCommandDTO.h"

@implementation KBaseSearchCommandDTO
@synthesize page =_page, rows = _rows;
@synthesize search = _search, dateForm = _dateForm, dateTo = _dateTo, fileTypeText = _fileTypeText, fileType = _fileType;

- (id)initWithSessionID:(NSString *)sessionID {
    self = [self init];
    
    if (self) {
        self.sessionID = sessionID;
		self.module = kAPI_MODULE;
		self.ajaxAction = kAPI_AJAX_VALUE;
		self.page = 1;
		self.rows = kRowsInPerPage;
    }
    
    return self;
}

- (NSMutableDictionary *)dictionary {
	NSMutableDictionary *dic = [super dictionary];
	
	if (dic) {
		[dic setValue:[NSString stringWithFormat:@"%d", self.page] forKey:kKEY_PAGE_NUMBER];
		[dic setValue:[NSString stringWithFormat:@"%d", self.rows] forKey:kKEY_ROWS_NUMBER];
		
		[dic setValue:self.search forKey:kKEY_SEARCH];
		[dic setValue:self.fileTypeText forKey:kKEY_FILE_TYPE];
		
		NSDateFormatter *dateFormatter = 
		[[NSDateFormatter alloc] init];
		dateFormatter.dateFormat = @"m/d/y";
		[dic setValue:[dateFormatter stringFromDate:self.dateForm] forKey:kKEY_DATE_FROM];
		[dic setValue:[dateFormatter stringFromDate:self.dateTo] forKey:kKEY_DATE_TO];
		
	}
	
	return dic;
}

- (NSString *)JSONString {
	return [[self dictionary] JSONString];
}

- (void)reset {
	self.page = 1;
	self.rows = kRowsInPerPage;
	self.search = @"";
	self.dateForm = nil;
	self.dateTo = nil;
}
@end
